package com.liik.game;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;


public class GameActivity extends Activity {

	protected GameSurfaceView gameSurfaceView;
	protected final ScreenHolder screenHolder;
	protected GameThread gameThread;
	
	public GameActivity(ScreenHolder screenHolder) {
		this.screenHolder = screenHolder;
	}

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		gameSurfaceView = new GameSurfaceView(this, screenHolder);
		gameThread = gameSurfaceView.getThread();
		setContentView(gameSurfaceView);
		 if (savedInstanceState == null) { // we were just launched: set up a new game
			screenHolder.resetState();
		 } else { // we are being restored: resume a previous game
		 	screenHolder.restoreState(savedInstanceState);
		 }
		 screenHolder.setContext(this);
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		screenHolder.saveState(outState);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		return true;
	}

	@Override
	protected void onDestroy() {
		Log.i("Activity", "onDestroy()");
		super.onDestroy();
		screenHolder.onDestroy();
	}

	@Override
	protected void onStop() {
		Log.i("Activity", "onStop()");
		super.onStop();
		screenHolder.onStop();
	}

	@Override
	protected void onPause() {
		Log.i("Activity", "onPause()");
		super.onPause();
		gameThread.setPaused(true);
		screenHolder.onPause();
	}

	@Override
	protected void onResume() {
		Log.i("Activity", "onResume()");
		super.onResume();
		gameThread.setPaused(false);
		screenHolder.onResume();
	}
}